####Replication Data for Figure 1 from "Why Most Ukrainians Feel Anger, Hatred, or Contempt toward Russian Citizens after the 2022 Russian Invasion?"##########
####by Kostantin Ash and Miroslav Shapovalov. Forthcoming in Political Psychology##############################################################################


library(ggplot2)
library(scales) 
library(reshape2)
library(foreign)






conf=.95
title="Age and Active Negative Emotion toward Russian Citizens"
xlabel="Surveyed After 2022 Russian Invasion of Ukraine"
ylabel="Likelihood of feeling Active Negative Emotion"
factor_labels=c("No","Yes")


# Get coefficients of variables
beta_1 =    .0040001
beta_3 =    -.0173301

# Create list of moderator values at which marginal effect is evaluated
x_2 <- c(0,1)

# Compute marginal effects
delta_1 = beta_1 + beta_3*x_2

# Compute variances
var_1 =   .00001411   + (x_2^2)*   -.00001411   + 2*x_2* .00004264  

# Standard errors
se_1 = se_1 = sqrt(var_1)

# Upper and lower confidence bounds
z_score = qnorm(1 - ((1 - conf)/2))
upper_bound = delta_1 + z_score*se_1
lower_bound = delta_1 - z_score*se_1

# Determine the bounds of the graphing area
max_y = max(upper_bound)
min_y = min(lower_bound)

# Initialize plotting window
plot(x=c(), y=c(), ylim=c(min_y, max_y), xlim=c(-.5, 1.5), xlab=xlabel, ylab=ylabel, main=title, xaxt="n")

# Plot points of estimated effects
points(x=x_2, y=delta_1, pch=16)

# Plot lines of confidence intervals
lines(x=c(x_2[1], x_2[1]), y=c(upper_bound[1], lower_bound[1]), lty=1)
points(x=c(x_2[1], x_2[1]), y=c(upper_bound[1], lower_bound[1]), pch=c(25,24), bg="black")
lines(x=c(x_2[2], x_2[2]), y=c(upper_bound[2], lower_bound[2]), lty=1)
points(x=c(x_2[2], x_2[2]), y=c(upper_bound[2], lower_bound[2]), pch=c(25,24), bg="black")

# Label the axis
axis(side=1, at=c(0,1), labels=factor_labels)

# Add a dashed horizontal line for zero
abline(h=0, lty=3)



conf=.95
title="Eastern Oblasts and \nActive Negative Emotion toward Russian Citizens"
xlabel="Surveyed After 2022 Russian Invasion of Ukraine"
ylabel="Likelihood of feeling Active Negative Emotion"
factor_labels=c("No","Yes")


# Get coefficients of variables
beta_1 =   -1.500586
beta_3 =   1.184905

# Create list of moderator values at which marginal effect is evaluated
x_2 <- c(0,1)

# Compute marginal effects
delta_1 = beta_1 + beta_3*x_2

# Compute variances
var_1 =   .19040522  + (x_2^2)*   -.19040522   + 2*x_2*  .36282773  

# Standard errors
se_1 = se_1 = sqrt(var_1)

# Upper and lower confidence bounds
z_score = qnorm(1 - ((1 - conf)/2))
upper_bound = delta_1 + z_score*se_1
lower_bound = delta_1 - z_score*se_1

# Determine the bounds of the graphing area
max_y = max(upper_bound)
min_y = min(lower_bound)

# Initialize plotting window
plot(x=c(), y=c(), ylim=c(min_y, max_y), xlim=c(-.5, 1.5), xlab=xlabel, ylab=ylabel, main=title, xaxt="n")

# Plot points of estimated effects
points(x=x_2, y=delta_1, pch=16)

# Plot lines of confidence intervals
lines(x=c(x_2[1], x_2[1]), y=c(upper_bound[1], lower_bound[1]), lty=1)
points(x=c(x_2[1], x_2[1]), y=c(upper_bound[1], lower_bound[1]), pch=c(25,24), bg="black")
lines(x=c(x_2[2], x_2[2]), y=c(upper_bound[2], lower_bound[2]), lty=1)
points(x=c(x_2[2], x_2[2]), y=c(upper_bound[2], lower_bound[2]), pch=c(25,24), bg="black")

# Label the axis
axis(side=1, at=c(0,1), labels=factor_labels)

# Add a dashed horizontal line for zero
abline(h=0, lty=3)



conf=.95
title="No Division by Language and \nActive Negative Emotion toward Russian Citizens"
xlabel="Surveyed After 2022 Russian Invasion of Ukraine"
ylabel="Likelihood of feeling Active Negative Emotion "
factor_labels=c("No","Yes")


# Get coefficients of variables
beta_1 =   -.4625522
beta_3 =     .1997411

# Create list of moderator values at which marginal effect is evaluated
x_2 <- c(0,1)

# Compute marginal effects
delta_1 = beta_1 + beta_3*x_2

# Compute variances
var_1 =  .0052641   + (x_2^2)*   -.0052641    + 2*x_2* .01234497   

# Standard errors
se_1 = se_1 = sqrt(var_1)

# Upper and lower confidence bounds
z_score = qnorm(1 - ((1 - conf)/2))
upper_bound = delta_1 + z_score*se_1
lower_bound = delta_1 - z_score*se_1

# Determine the bounds of the graphing area
max_y = max(upper_bound)
min_y = min(lower_bound)

# Initialize plotting window
plot(x=c(), y=c(), ylim=c(min_y, max_y), xlim=c(-.5, 1.5), xlab=xlabel, ylab=ylabel, main=title, xaxt="n")

# Plot points of estimated effects
points(x=x_2, y=delta_1, pch=16)

# Plot lines of confidence intervals
lines(x=c(x_2[1], x_2[1]), y=c(upper_bound[1], lower_bound[1]), lty=1)
points(x=c(x_2[1], x_2[1]), y=c(upper_bound[1], lower_bound[1]), pch=c(25,24), bg="black")
lines(x=c(x_2[2], x_2[2]), y=c(upper_bound[2], lower_bound[2]), lty=1)
points(x=c(x_2[2], x_2[2]), y=c(upper_bound[2], lower_bound[2]), pch=c(25,24), bg="black")

# Label the axis
axis(side=1, at=c(0,1), labels=factor_labels)

# Add a dashed horizontal line for zero
abline(h=0, lty=3)


conf=.95
title="USSR History is Our History \nand Active Negative Emotion toward Russian Citizens"
xlabel="Surveyed After 2022 Russian Invasion of Ukraine"
ylabel="Likelihood of feeling Active Negative Emotion "
factor_labels=c("No","Yes")


# Get coefficients of variables
beta_1 =   -.3042297 
beta_3 =    .1384475

# Create list of moderator values at which marginal effect is evaluated
x_2 <- c(0,1)

# Compute marginal effects
delta_1 = beta_1 + beta_3*x_2

# Compute variances
var_1 =   .0037905   + (x_2^2)*   -.0037905   + 2*x_2* .00628676 

# Standard errors
se_1 = se_1 = sqrt(var_1)

# Upper and lower confidence bounds
z_score = qnorm(1 - ((1 - conf)/2))
upper_bound = delta_1 + z_score*se_1
lower_bound = delta_1 - z_score*se_1

# Determine the bounds of the graphing area
max_y = max(upper_bound)
min_y = min(lower_bound)

# Initialize plotting window
plot(x=c(), y=c(), ylim=c(min_y, max_y), xlim=c(-.5, 1.5), xlab=xlabel, ylab=ylabel, main=title, xaxt="n")

# Plot points of estimated effects
points(x=x_2, y=delta_1, pch=16)

# Plot lines of confidence intervals
lines(x=c(x_2[1], x_2[1]), y=c(upper_bound[1], lower_bound[1]), lty=1)
points(x=c(x_2[1], x_2[1]), y=c(upper_bound[1], lower_bound[1]), pch=c(25,24), bg="black")
lines(x=c(x_2[2], x_2[2]), y=c(upper_bound[2], lower_bound[2]), lty=1)
points(x=c(x_2[2], x_2[2]), y=c(upper_bound[2], lower_bound[2]), pch=c(25,24), bg="black")

# Label the axis
axis(side=1, at=c(0,1), labels=factor_labels)

# Add a dashed horizontal line for zero
abline(h=0, lty=3)

